<?php session_start();?>
<?php require_once('Connections/database.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
if(isset($_POST["TenDangNhap"]))
{
mysql_select_db($database_database, $database);
$query_User = "SELECT * FROM nguoidung WHERE TenDangNhap = '".trim($_POST["TenDangNhap"])."' AND MatKhau = '".trim($_POST["MatKhau"])."'";
$User = mysql_query($query_User, $database) or die(mysql_error());
$row_User = mysql_fetch_assoc($User);
$totalRows_User = mysql_num_rows($User);
if($totalRows_User  == 1)
{
	$_SESSION['user'] = $row_User["TenDangNhap"];	
	header(sprintf("Location: index.php"));
	
	echo $_SESSION['user'] ;
}
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="vi-vn" lang="vi-vn">
    <head>
        <title>Login</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <link href="Content/style.css" rel="stylesheet" type="text/css" />
    	<script src="Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            function RedirectToHome() {
                var link = '/admin';
                window.location.replace(link);
            }
        </script>
    </head>
    <body class="loginbg">
        <div id="wrap">
            <form method="post" action="login.php">
                <div class="logindivwrap">
                    <div class="logindivtitle">Đăng nhập trang quản trị</div>
                    <div class="logindiv">
                        <div class="loginatributelabel loginmargintop">Tên đăng nhập:</div>
                        <div class="loginatributeeditor loginmargintop"><input type="text" class="input250" name="TenDangNhap" id="TenDangNhap"/></div>
                        <div class="clear">&nbsp;</div>
                        <div class="loginatributelabel">Mật khẩu:</div>
                        <div class="loginatributeeditor"><input type="password" class="input250" name="MatKhau" id="MatKhau"/></div>
                        <div class="clear">&nbsp;</div>
                        <div class="loginatributelabel">&nbsp;</div>
                        <div class="loginatributeeditor">
                            <input type="submit" value="Đăng nhập"/>&nbsp;&nbsp;&nbsp;
                            <input type="button" value="Trang chủ" onclick="RedirectToHome();"/>
                        </div>
                        <div class="clear">&nbsp;</div>
                    </div>
                </div>
            </form>
        </div>
    </body>
</html>
<?php
if(isset($_POST["TenDangNhap"]))
{
mysql_free_result($User);
}
?>
